package org.dftproject.gedcom.ui.pages;

import java.io.File;

import org.dftproject.gedcom.ui.Activator;
import org.dftproject.genesis.ui.pages.AbstractPageInput;

public class GedcomPageInput extends AbstractPageInput {
	
	private String filename;
	
	public GedcomPageInput(String filename) {
		setFilename(filename);
	}
	
	public String getFilename() {
		return filename;
	}
	
	public void setFilename(String filename) {
		this.filename = filename;
		setLabel(getName(filename));
		setImageDescriptor(Activator.getImageDescriptor("icons/page.png"));
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((filename == null) ? 0 : filename.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final GedcomPageInput other = (GedcomPageInput) obj;
		if (filename == null) {
			if (other.filename != null)
				return false;
		} else if (!filename.equals(other.filename))
			return false;
		return true;
	}
	
	protected String getName(String path) {
		File file = new File(path);
		return file.getName().replaceFirst("\\.[^.]*$", "");
	}

}
